var request = require('request');
var async = require('async');
var cheerio = require('cheerio');
var URL = require('url');
var mongodb = require('./mongodb.js');
require('./Math.uuid.js');
var fs = require('fs');
var Ut = {};
var file="D:/workSpace/contract/data/modelfile/";//提交时需要更改D:/workSpace/contract/data     /aldata/www/jianfa.com
var filePath="/download/cpppcFile_yao/";


//数据库表名
var cppp_org_item = "cfw_cpppc_org_item_yao";
var errorInitial = "cfw_cpppc_org_error_yao";


var cpppc_url="http://www.cpppc.org:8082/efmisweb";


Ut.get_company_list_ceshi = function (queryPage,callback) {
    var distArr = new Array();				// 地区过滤条件
    var induArr = new Array();				// 行业过滤条件
    var investArr = new Array();			// 金额过滤条件
    //后台实现多选，前台做成单选       2016-03-11
    var stageArr = new Array();				//项目阶段条件

    var projName = "";	// 项目名称搜索
    var sortby = "";						// 排序字段
    var orderby = "";						// 排序顺序
    var level = "";	// 示范级别


    var requestData = {
        queryPage : queryPage,
        distStr : distArr.join(),
        induStr : induArr.join(),
        investStr : investArr.join(),
        projName : projName,
        sortby : sortby,
        orderby : orderby,
        level : level,
        stageArr :　stageArr.join()
    }

    var  options = {
        url: cpppc_url+'/ppp/projectLibrary/getPPPList.do',
        method: "POST",
        json: true,
        headers: {
            "content-type": "application/json",
        },
        body: JSON.stringify(requestData)
    };
    request(options, function (err, res, body) {
        if (err) {
            console.log(err)
        }else {
            //console.log(body.currentPage+"===="+body.totalCount);//totalPage
            //判断不为undefined并且有数据
            if(body != undefined && body.totalCount > 0){
                //循环获取返回的list集合信息
                if(body.list != null && body.list.length > 0){
                    body.list.forEach(function (cpppcJson, index) {
                        var data = cpppcJson;

                        data.proj_href = cpppc_url+"/ppp/projectLibrary/getProjInfoNational.do?projId="+cpppcJson.PROJ_RID;//项目详细地址
                        data.proj_name = cpppcJson.PROJ_NAME;//项目名称
                        data.proj_state = cpppcJson.PROJ_STATE;//所处阶段
                        data.proj_state_name = cpppcJson.PROJ_STATE_NAME;//所处阶段（1、识别阶段  2、准备阶段  3、采购阶段  4、执行阶段  5、移交阶段）
                        data.prv = cpppcJson.PRV;//所在地区(省-市-县)
                        data.prv1 = cpppcJson.PRV1;//省
                        data.prv2 = cpppcJson.PRV2;//市
                        data.prv3 = cpppcJson.PRV3;//县
                        data.ivalue = cpppcJson.IVALUE;//所属行业（一级分类）
                        data.ivalue2 = cpppcJson.IVALUE2;//所属行业（二级分类）
                        data.investcount = cpppcJson.INVESTCOUNT;//项目总投资(单位：万元)
                        data.proj_survey = cpppcJson.PROJ_SURVEY;//项目调查(项目概况(识别))
                        data.start_time = cpppcJson.START_TIME;//发起时间
                        data.proj_rid = cpppcJson.PROJ_RID;//项目id
                        data.return_mode_name = cpppcJson.RETURN_MODE_NAME;//回报机制
                        data.proj_level = cpppcJson.PROJ_LEVEL;//示范级别（1、国家示范项目  2、省级示范项目  4、其它）(同code_name对应)
                        data.code_name = cpppcJson.CODE_NAME;//项目示范级别/批次(同proj_level对应)
                        data.link_uname = cpppcJson.LINK_UNAME;//项目联系人
                        data.link_tel = cpppcJson.LINK_TEL;//联系电话
                        data.estimate_coper = cpppcJson.ESTIMATE_COPER;//合作期限
                        data.operate_mode_name = cpppcJson.OPERATE_MODE_NAME;//项目运作方式
                        data.publ_time = cpppcJson.PUBL_TIME;//项目发布时间(详情页)
                        data.publ_ppp_time = cpppcJson.PUBL_PPP_TIME;//项目发布时间





                        data.sign = cpppcJson.SIGN;
                        data.local_linktel = cpppcJson.LOCAL_LINKTEL;
                        data.implorg_phone = cpppcJson.IMPLORG_PHONE;
                        data.proj_no = cpppcJson.PROJ_NO;
                        data.invest_count = cpppcJson.INVEST_COUNT;
                        data.remark = cpppcJson.REMARK;
                        data.report_status = cpppcJson.REPORT_STATUS;
                        data.rn = cpppcJson.RN;
                        data.operate_mode = cpppcJson.OPERATE_MODE;
                        data.proj_seq = cpppcJson.PROJ_SEQ;
                        data.rev_ = cpppcJson.REV_;
                        data.industry_audit = cpppcJson.INDUSTRY_AUDIT;
                        data.prep_createtime = cpppcJson.PREP_CREATETIME;
                        data.start_uname = cpppcJson.START_UNAME;
                        data.industry_img = cpppcJson.INDUSTRY_IMG;
                        data.quit_apply_time = cpppcJson.QUIT_APPLY_TIME;
                        data.proj_area = cpppcJson.PROJ_AREA;
                        data.publ_state = cpppcJson.PUBL_STATE;
                        data.proj_url = cpppcJson.PROJ_URL;
                        data.industry_required = cpppcJson.INDUSTRY_REQUIRED;
                        data.implorg = cpppcJson.IMPLORG;
                        data.proj_type_name = cpppcJson.PROJ_TYPE_NAME;
                        data.implorg_linkman = cpppcJson.IMPLORG_LINKMAN;
                        data.charge_dept = cpppcJson.CHARGE_DEPT;
                        data.lock_time = cpppcJson.LOCK_TIME;
                        data.creating_uname = cpppcJson.CREATING_UNAME;
                        data.purc_createtime = cpppcJson.PURC_CREATETIME;
                        data.exit_status = cpppcJson.EXIT_STATUS;
                        data.industry_sub = cpppcJson.INDUSTRY_SUB;
                        data.industry_optional = cpppcJson.INDUSTRY_OPTIONAL;
                        data.publ_ppp_state = cpppcJson.PUBL_PPP_STATE;
                        data.creating_uid = cpppcJson.CREATING_UID;
                        data.updating_time = cpppcJson.UPDATING_TIME;
                        data.transfer_createtime = cpppcJson.TRANSFER_CREATETIME;
                        data.lock_status = cpppcJson.LOCK_STATUS;
                        data.industry_required_new = cpppcJson.INDUSTRY_REQUIRED_NEW;
                        data.central_status = cpppcJson.CENTRAL_STATUS;
                        data.ppp_level = cpppcJson.PPP_LEVEL;
                        data.updating_uid = cpppcJson.UPDATING_UID;
                        data.attach_notice = cpppcJson.ATTACH_NOTICE;
                        data.iden_createtime = cpppcJson.IDEN_CREATETIME;
                        data.dist_code = cpppcJson.DIST_CODE;
                        data.database_name = cpppcJson.DATABASE_NAME;
                        data.database_type = cpppcJson.DATABASE_TYPE;
                        data.quit_audit_state = cpppcJson.QUIT_AUDIT_STATE;
                        data.eval_org = cpppcJson.EVAL_ORG;
                        data.quit_time = cpppcJson.QUIT_TIME;
                        data.prep_rid = cpppcJson.PREP_RID;
                        data.close_state = cpppcJson.CLOSE_STATE;
                        data.quit_type = cpppcJson.QUIT_TYPE;
                        data.audit_state = cpppcJson.AUDIT_STATE;
                        data.return_mode = cpppcJson.RETURN_MODE;
                        data.ext_1 = cpppcJson.EXT_1;
                        data.industry_audit_advice = cpppcJson.INDUSTRY_AUDIT_ADVICE;
                        data.start_type = cpppcJson.START_TYPE;
                        data.local_linkman = cpppcJson.LOCAL_LINKMAN;
                        data.ext_2 = cpppcJson.EXT_2;
                        data.updating_uname = cpppcJson.UPDATING_UNAME;
                        data.exec_createtime = cpppcJson.EXEC_CREATETIME;

                        data.proj_type = cpppcJson.PROJ_TYPE;
                    });
                }
            }
        }
    })







}
Ut.query_total_page = function (callback) {
    var  options = {
        url: cpppc_url+"/ppp/projectLibrary/getPPPList.do",
        method: "POST",
        json: true,
        headers: {
            "content-type": "application/json",
        }
    };
    request(options, function (err, res, body) {
        if (err) {
            console.log("err===========", err)
        } else {
            return callback(null, body);
        }
    });
}


Ut.query_cpppc_org_list = function (queryPage, trs, callback) {
     var  options = {
        url: cpppc_url+"/ppp/projectLibrary/getPPPList.do?queryPage="+queryPage,
        method: "POST",
        json: true,
        headers: {
            "content-type": "application/json",
        }
    };
    request(options, function (err, res, body) {
        if (err) {
            console.log("err===========",err)
        }else {
            //console.log(body.currentPage+"===="+body.totalPage);//totalPage
            //判断不为undefined并且有数据 并且循环获取返回的list集合信息
            if(body != undefined && body.list != null && body.list.length > 0){
                body.list.forEach(function (cpppcJson, index) {
                    var proUrl= cpppc_url+"/ppp/projectLibrary/getProjInfoNational.do?projId="+cpppcJson.PROJ_RID;
                    cpppcJson.PROJ_HREF = proUrl;//项目详细地址
                    cpppcJson.INVESTCOUNT = cpppcJson.INVESTCOUNT.trim();//项目总投资(单位：万元)
                    //cpppcJson.IVALUE_DEFINED = Ut.classifyType(cpppcJson.IVALUE);//所属行业（一级分类）
                    //cpppcJson.IVALUE2_DEFINED = cpppcJson.IVALUE2;//所属行业（二级分类）
                    //cpppcJson.PRV1_DEFINED = Ut.region_num(cpppcJson.PRV1);//省
                    //cpppcJson.PRV2_DEFINED = Ut.region_num(cpppcJson.PRV2);//市
                    //cpppcJson.PRV3_DEFINED = cpppcJson.PRV3;//县
                    //cpppcJson.STATUS = 0;
                    cpppcJson.CREATE_TIME_UPDATE = new Date();
                    trs.push(cpppcJson);

                });
            }
            console.log("==============查询完成方法===========跳出======",trs.length)
            if (trs.length == 0) return callback("无符合条件数据", null);
            return callback(null, trs);
        }
    })
}

Ut.get_cpppc_org_detail = function (dataArray, callback) {
    console.log("==dataArray==",dataArray.length)
    var task1 = []; //顺序执行
    dataArray.forEach(function (json, index) {
        task1.push(function (callback) {
            console.log(index,"==json.PROJ_HREF==",json.PROJ_HREF)
            var is_update = 1;
            request({url:json.PROJ_HREF,timeout: 5000}, function (err, response, html) {
                var query = {
                    'PROJ_HREF': json.PROJ_HREF
                };
                var oldJSON = null;//数据库中当前链接对象
                mongodb.query(cppp_org_item, query, function (err, res) {
                    //判断对象不为空、则判断当前数据和数据库中的数据对比，是否有
                    if(res != null && res != undefined && res.length > 0){
                        oldJSON = res[0];
                    }else{
                        is_update = 2;
                    }

                try {
                    var $ = cheerio.load(html);
                    //获取数据
                    //获取当前项目的示范级别
                    var viewTaObj = $(".view_table");
                    var tableTr = $(viewTaObj[0]).find('tr');
                    var text = $(tableTr[5]).find('td').eq(1).text().trim();
                    if(text == null || text == ""){
                        text = json.CODE_NAME;
                    }
                    json.CODE_NAME_TEXT = text;
                    json.CODE_NAME_TEXT_DEFINED = text;//部署删除
                    if(text.indexOf("国家示范项目") > 0){
                        json.CODE_NAME_VALUE = 1;
                        json.CODE_NAME_VALUE_DEFINED = 1;//部署删除
                    }else if(text.indexOf("省级示范项目") > 0){
                        json.CODE_NAME_VALUE = 2;
                        json.CODE_NAME_VALUE_DEFINED = 2;//部署删除
                    }else{
                        json.CODE_NAME_VALUE = 4;
                        json.CODE_NAME_VALUE_DEFINED = 4;//部署删除
                    }
                    console.log("----------------------------------------------------------------------",json.CODE_NAME_TEXT,"====text====",json.CODE_NAME_VALUE)

                    var projState = json.PROJ_STATE;
                    json.UPDATE_TIME = new Date();
                    //获取识别阶段信息
                    if(projState >= 1){
                        var tables1 = $("#con_ss_1").find('table');
                        //获取即时公开信息
                        var trs1 = $(tables1[0]).find('tr');
                        json.PROJ_SITUATION_SHIBIE = $(trs1[0]).find('td').eq(1).text().trim();//项目概况(识别)
                        json.PROJ_COOPERATION_SHIBIE = $(trs1[1]).find('td').eq(1).text().trim();//项目合作范围(识别)
                        json.ESTIMATE_COPER_SHIBIE = $(trs1[2]).find('td').eq(1).text().trim();//合作期限(准备)
                        json.OPERATE_MODE_NAME_SHIBIE = $(trs1[2]).find('td').eq(3).text().trim();//项目运作方式(准备)
                        json.PROCUREMENT_METHOD = $(trs1[3]).find('td').eq(1).text().trim();//采购社会资本方式
                        json.REPORT_AUDIT_OPINION = $(trs1[5]).find('td').eq(1).text().trim();//物有所值评价通过与否的评价结论（含财政部门对报告的审核意见）
                        json.FISCAL_BEARING_CAPACITY = $(trs1[9]).find('td').eq(1).text().trim();//通过财政承受能力论证与否的结论
                        //抓取--即时公开附件--信息
                        //获取---物有所值定性评价指标及权重、评分标准、评分结果---附件
                        var url_app = $(trs1[4]).find('td').eq(1).find('a');
                        var assessmentCriteriaList = new Array();
                        var assessmentCriteriaListNew = new Array();
                        $(url_app).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            //获取URL地址
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.ASSESSMENT_CRITERIA_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    assessmentCriteriaList = dataArraya;
                                    assessmentCriteriaListNew = oldJSON.ASSESSMENT_CRITERIA_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 1,json.PROJ_HREF,callback);
                                        assessmentCriteriaList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        assessmentCriteriaListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    assessmentCriteriaList.push(Ut.save_accessory_pdf(ob, 1,json.PROJ_HREF,callback));
                                }
                            }else{
                                assessmentCriteriaList.push(Ut.save_accessory_pdf(ob, 1,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.ASSESSMENT_CRITERIA_REPORTS = assessmentCriteriaList;
                        }else{
                            json.ASSESSMENT_CRITERIA_REPORTS = assessmentCriteriaListNew;
                        }
                        json.ASSESSMENT_CRITERIA_REPORTS_S = assessmentCriteriaList;

                        //获取---财政承受能力论证的测算依据、主要因素和指标---附件
                        var url_argument = $(trs1[8]).find('td').eq(1).find('a');
                        var argumentMeasureList = new Array();
                        var argumentMeasureListNew = new Array();
                        $(url_argument).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.ARGUMENT_MEASURE_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    argumentMeasureList = dataArraya;
                                    argumentMeasureListNew = oldJSON.ARGUMENT_MEASURE_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 2,json.PROJ_HREF,callback);
                                        argumentMeasureList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        argumentMeasureListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    argumentMeasureList.push(Ut.save_accessory_pdf(ob, 2,json.PROJ_HREF,callback));
                                }
                            }else{
                                argumentMeasureList.push(Ut.save_accessory_pdf(ob, 2,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.ARGUMENT_MEASURE_REPORTS = argumentMeasureList;
                        }else{
                            json.ARGUMENT_MEASURE_REPORTS = argumentMeasureListNew;
                        }
                        json.ARGUMENT_MEASURE_REPORTS_S = argumentMeasureList;

                        //抓取--适时公开附件--信息
                        var trsPDF1 = $(tables1[2]).find('tr');//附件信息所在的table表格数据栏
                        //获取---物有所值评价报告及本级行业主管部门会同财政部门的审核通过意见---附件
                        var url_app = $(trsPDF1[0]).find('td').eq(1).find('a');
                        var appraiseList = new Array();
                        var appraiseListNew = new Array();
                        $(url_app).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.APPRAISE_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    appraiseList = dataArraya;
                                    appraiseListNew = oldJSON.APPRAISE_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 3,json.PROJ_HREF,callback);
                                        appraiseList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        appraiseListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    appraiseList.push(Ut.save_accessory_pdf(ob, 3,json.PROJ_HREF,callback));
                                }
                            }else{
                                appraiseList.push(Ut.save_accessory_pdf(ob, 3,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.APPRAISE_REPORTS = appraiseList;
                        }else{
                            json.APPRAISE_REPORTS = appraiseListNew;
                        }
                        json.APPRAISE_REPORTS_S = appraiseList;
                        //获取---财政承受能力论证报告及本级财政部门的审核通过意见---附件
                        var url_arg = $(trsPDF1[1]).find('td').eq(1).find('a');
                        var argumentList = new Array();
                        var argumentListNew = new Array();
                        $(url_arg).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.ARGUMENT_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    argumentList = dataArraya;
                                    argumentListNew = oldJSON.ARGUMENT_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 4,json.PROJ_HREF,callback);
                                        argumentList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        argumentListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    argumentList.push(Ut.save_accessory_pdf(ob, 4,json.PROJ_HREF,callback));
                                }
                            }else{
                                argumentList.push(Ut.save_accessory_pdf(ob, 4,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.ARGUMENT_REPORTS = argumentList;
                        }else{
                            json.ARGUMENT_REPORTS = argumentListNew;
                        }
                        json.ARGUMENT_REPORTS_S = argumentList;
                        //获取---新建或改扩建项目建议书及批复文件---附件
                        var url_exp = $(trsPDF1[2]).find('td').eq(1).find('a');
                        var expandList = new Array();
                        var expandListNew = new Array();
                        $(url_exp).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.EXPAND_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    expandList = dataArraya;
                                    expandListNew = oldJSON.EXPAND_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 5,json.PROJ_HREF,callback);
                                        expandList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        expandListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    expandList.push(Ut.save_accessory_pdf(ob, 5,json.PROJ_HREF,callback));
                                }
                            }else{
                                expandList.push(Ut.save_accessory_pdf(ob, 5,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.EXPAND_REPORTS = expandList;
                        }else{
                            json.EXPAND_REPORTS = expandListNew;
                        }
                        json.EXPAND_REPORTS_S = expandList;
                        //获取---可行性研究报告（含全套支撑性文件）及批复文件---附件
                        var url_fea = $(trsPDF1[3]).find('td').eq(1).find('a');
                        var feasibilityList = new Array();
                        var feasibilityListNew = new Array();
                        $(url_fea).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.FEASIBILITY_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    feasibilityList = dataArraya;
                                    feasibilityListNew = oldJSON.FEASIBILITY_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 6,json.PROJ_HREF,callback);
                                        feasibilityList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        feasibilityListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    feasibilityList.push(Ut.save_accessory_pdf(ob, 6,json.PROJ_HREF,callback));
                                }
                            }else{
                                feasibilityList.push(Ut.save_accessory_pdf(ob, 6,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.FEASIBILITY_REPORTS = feasibilityList;
                        }else{
                            json.FEASIBILITY_REPORTS = feasibilityListNew;
                        }
                        json.FEASIBILITY_REPORTS_S = feasibilityList;
                        //获取---设计文件及批复文件---附件
                        var url_des = $(trsPDF1[4]).find('td').eq(1).find('a');
                        var designList = new Array();
                        var designListNew = new Array();
                        $(url_des).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.DESIGN_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    designList = dataArraya;
                                    designListNew = oldJSON.DESIGN_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 7,json.PROJ_HREF,callback);
                                        designList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        designListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    designList.push(Ut.save_accessory_pdf(ob, 7,json.PROJ_HREF,callback));
                                }
                            }else{
                                designList.push(Ut.save_accessory_pdf(ob, 7,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.DESIGN_REPORTS = designList;
                        }else{
                            json.DESIGN_REPORTS = designListNew;
                        }
                        json.DESIGN_REPORTS_S = designList;
                        //获取---存量公共资产或权益的资产评估报告，以及存量资产或权益转让时所可能涉及到的各类方案等---附件
                        var url_ass = $(trsPDF1[5]).find('td').eq(1).find('a');
                        var assetsAppraisalList = new Array();
                        var assetsAppraisalListNew = new Array();
                        $(url_ass).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.ASSETS_APPRAISAL_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    assetsAppraisalList = dataArraya;
                                    assetsAppraisalListNew = oldJSON.ASSETS_APPRAISAL_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 8,json.PROJ_HREF,callback);
                                        assetsAppraisalList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        assetsAppraisalListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    assetsAppraisalList.push(Ut.save_accessory_pdf(ob, 8,json.PROJ_HREF,callback));
                                }
                            }else{
                                assetsAppraisalList.push(Ut.save_accessory_pdf(ob, 8,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.ASSETS_APPRAISAL_REPORTS = assetsAppraisalList;
                        }else{
                            json.ASSETS_APPRAISAL_REPORTS = assetsAppraisalListNew;
                        }
                        json.ASSETS_APPRAISAL_REPORTS_S = assetsAppraisalList;

                    }
                    //获取准备阶段信息
                    if(projState >= 2){
                        var tables2 = $("#con_ss_2").find('table');
                        //获取即时公开信息
                        var trs2 = $(tables2[0]).find('tr');
                        json.PROJ_SITUATION_ZHUNBEI = $(trs2[0]).find('td').eq(1).text().trim();//项目概况(准备)
                        json.PROJ_COOPERATION_ZHUNBEI = $(trs2[1]).find('td').eq(1).text().trim();//项目合作范围(准备)
                        json.ESTIMATE_COPER_ZHUNBEI = $(trs2[2]).find('td').eq(1).text().trim();//合作期限(识别)
                        json.OPERATE_MODE_NAME_ZHUNBEI = $(trs2[2]).find('td').eq(3).text().trim();//项目运作方式(识别)
                        //抓取--即时公开附件--信息
                        //获取---政府方授权文件，包括对实施机构、PPP项目合同的政府方签约主体、政府方出资代表等的授权---附件
                        var url_author = $(trs2[4]).find('td').eq(1).find('a');
                        var authorizationDocumentList = new Array();
                        var authorizationDocumentListNew = new Array();
                        $(url_author).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.AUTHORIZATION_DOCUMENT_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    authorizationDocumentList = dataArraya;
                                    authorizationDocumentListNew = oldJSON.AUTHORIZATION_DOCUMENT_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 9,json.PROJ_HREF,callback);
                                        authorizationDocumentList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        authorizationDocumentListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    authorizationDocumentList.push(Ut.save_accessory_pdf(ob, 9,json.PROJ_HREF,callback));
                                }
                            }else{
                                authorizationDocumentList.push(Ut.save_accessory_pdf(ob, 9,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.AUTHORIZATION_DOCUMENT_REPORTS = authorizationDocumentList;
                        }else{
                            json.AUTHORIZATION_DOCUMENT_REPORTS = authorizationDocumentListNew;
                        }
                        json.AUTHORIZATION_DOCUMENT_REPORTS_S = authorizationDocumentList;
                        //获取---政府对实施方案的审核通过文件---附件
                        var url_execu = $(trs2[5]).find('td').eq(1).find('a');
                        var executeSolutionAuditList = new Array();
                        var executeSolutionAuditListNew = new Array();
                        $(url_execu).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.EXECUTE_SOLUTION_AUDIT_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    executeSolutionAuditList = dataArraya;
                                    executeSolutionAuditListNew = oldJSON.EXECUTE_SOLUTION_AUDIT_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 10,json.PROJ_HREF,callback);
                                        executeSolutionAuditList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        executeSolutionAuditListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    executeSolutionAuditList.push(Ut.save_accessory_pdf(ob, 10,json.PROJ_HREF,callback));
                                }
                            }else{
                                executeSolutionAuditList.push(Ut.save_accessory_pdf(ob, 10,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.EXECUTE_SOLUTION_AUDIT_REPORTS = executeSolutionAuditList;
                        }else{
                            json.EXECUTE_SOLUTION_AUDIT_REPORTS = executeSolutionAuditListNew;
                        }
                        json.EXECUTE_SOLUTION_AUDIT_REPORTS_S = executeSolutionAuditList;

                        //抓取--适时公开附件--信息
                        var trsPDF2 = $(tables2[1]).find('tr');//附件信息所在的table表格数据栏
                        //获取---交易结构（含投融资结构、回报机制、相关配套安排）、项目产出说明和绩效标准、风险分配框架、合同体系、监管体系---附件
                        var url_struct = $(trsPDF2[0]).find('td').eq(1).find('a');
                        var structureDealList = new Array();
                        var structureDealListNew = new Array();
                        $(url_struct).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.STRUCTURE_DEAL_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    structureDealList = dataArraya;
                                    structureDealListNew = oldJSON.STRUCTURE_DEAL_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 11,json.PROJ_HREF,callback);
                                        structureDealList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        structureDealListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    structureDealList.push(Ut.save_accessory_pdf(ob, 11,json.PROJ_HREF,callback));
                                }
                            }else{
                                structureDealList.push(Ut.save_accessory_pdf(ob, 11,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.STRUCTURE_DEAL_REPORTS = structureDealList;
                        }else{
                            json.STRUCTURE_DEAL_REPORTS = structureDealListNew;
                        }
                        json.STRUCTURE_DEAL_REPORTS_S = structureDealList;

                        //获取---审核通过的项目实施方案及修正案---附件
                        var url_amendment = $(trsPDF2[1]).find('td').eq(1).find('a');
                        var amendmentList = new Array();
                        var amendmentListNew = new Array();
                        $(url_amendment).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.AMENDMENT_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    amendmentList = dataArraya;
                                    amendmentListNew = oldJSON.AMENDMENT_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 12,json.PROJ_HREF,callback);
                                        amendmentList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        amendmentListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    amendmentList.push(Ut.save_accessory_pdf(ob, 12,json.PROJ_HREF,callback));
                                }
                            }else{
                                amendmentList.push(Ut.save_accessory_pdf(ob, 12,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.AMENDMENT_REPORTS = amendmentList;
                        }else{
                            json.AMENDMENT_REPORTS = amendmentListNew;
                        }
                        json.AMENDMENT_REPORTS_S = amendmentList;
                    }
                    //获取采购阶段信息
                    if(projState >= 3){
                        var tables3 = $("#con_ss_3").find('table');
                        //获取即时公开信息
                        var trs3 = $(tables3[0]).find('tr');

                        //抓取--即时公开附件--信息
                        //获取---项目资格预审公告（含资格预审申请文件）---附件
                        var url_prequa = $(trs3[0]).find('td').eq(1).find('a');
                        var prequalificationList = new Array();
                        var prequalificationListNew = new Array();
                        $(url_prequa).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.PREQUALIFICATION_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    prequalificationList = dataArraya;
                                    prequalificationListNew = oldJSON.PREQUALIFICATION_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 13,json.PROJ_HREF,callback);
                                        prequalificationList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        prequalificationListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    prequalificationList.push(Ut.save_accessory_pdf(ob, 13,json.PROJ_HREF,callback));
                                }
                            }else{
                                prequalificationList.push(Ut.save_accessory_pdf(ob, 13,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.PREQUALIFICATION_REPORTS = prequalificationList;
                        }else{
                            json.PREQUALIFICATION_REPORTS = prequalificationListNew;
                        }
                        json.PREQUALIFICATION_REPORTS_S = prequalificationList;


                        //获取---预中标及成交结果公告；中标、成交结果公告及中标通知书---附件
                        var url_bid = $(trs3[1]).find('td').eq(1).find('a');
                        var bidResultList = new Array();
                        var bidResultListNew = new Array();
                        $(url_bid).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.BID_RESULT_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    bidResultList = dataArraya;
                                    bidResultListNew = oldJSON.BID_RESULT_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 14,json.PROJ_HREF,callback);
                                        bidResultList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        bidResultListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    bidResultList.push(Ut.save_accessory_pdf(ob, 14,json.PROJ_HREF,callback));
                                }
                            }else{
                                bidResultList.push(Ut.save_accessory_pdf(ob, 14,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.BID_RESULT_REPORTS = bidResultList;
                        }else{
                            json.BID_RESULT_REPORTS = bidResultListNew;
                        }
                        json.BID_RESULT_REPORTS_S = bidResultList;

                        json.COMPETENT_DEPARTMENT = $(trs3[2]).find('td').eq(1).text().trim();//项目本级行业主管部门对拟签署PPP合同的审核意见
                        json.FINANCIAL_DEPARTMENT = $(trs3[3]).find('td').eq(1).text().trim();//项目本级财政部门对拟签署PPP合同的审核意见
                        json.LEGAL_INSTITUTION_DEPARTMENT = $(trs3[4]).find('td').eq(1).text().trim();//项目本级法制部门对拟签署PPP合同的审核意见

                        var peopleObj = $(trs3[5]).find('td');
                        var approvalDate="";
                        if(peopleObj != null && peopleObj.length == 4){
                            approvalDate = $(peopleObj).eq(3).text().trim();
                        }
                        json.PEOPLES_GOVERNMENT = $(peopleObj).eq(1).text().trim();//项目本级人民政府是否批准了拟签署的PPP合同
                        json.APPROVAL_DATE = approvalDate;//批准日期

                        //获取---PPP项目合同核心条款，应包括主要产出说明、绩效指标回报机制、调价机制---附件
                        var url_core = $(trs3[6]).find('td').eq(1).find('a');
                        var coreClausesList = new Array();
                        var coreClausesListNew = new Array();
                        $(url_core).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.CORE_CLAUSES_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    coreClausesList = dataArraya;
                                    coreClausesListNew = oldJSON.CORE_CLAUSES_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 15,json.PROJ_HREF,callback);
                                        coreClausesList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        coreClausesListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    coreClausesList.push(Ut.save_accessory_pdf(ob, 15,json.PROJ_HREF,callback));
                                }
                            }else{
                                coreClausesList.push(Ut.save_accessory_pdf(ob, 15,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.CORE_CLAUSES_REPORTS = coreClausesList;
                        }else{
                            json.CORE_CLAUSES_REPORTS = coreClausesListNew;
                        }
                        json.CORE_CLAUSES_REPORTS_S = coreClausesList;

                        //获取---项目采购阶段调整、更新的政府方授权文件---附件
                        var url_purchase = $(trs3[7]).find('td').eq(1).find('a');
                        var purchaseAdjustmentList = new Array();
                        var purchaseAdjustmentListNew = new Array();
                        $(url_purchase).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.PURCHASE_ADJUSTMENT_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    purchaseAdjustmentList = dataArraya;
                                    purchaseAdjustmentListNew = oldJSON.PURCHASE_ADJUSTMENT_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 16,json.PROJ_HREF,callback);
                                        purchaseAdjustmentList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        purchaseAdjustmentListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    purchaseAdjustmentList.push(Ut.save_accessory_pdf(ob, 16,json.PROJ_HREF,callback));
                                }
                            }else{
                                purchaseAdjustmentList.push(Ut.save_accessory_pdf(ob, 16,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.PURCHASE_ADJUSTMENT_REPORTS = purchaseAdjustmentList;
                        }else{
                            json.PURCHASE_ADJUSTMENT_REPORTS = purchaseAdjustmentListNew;
                        }
                        json.PURCHASE_ADJUSTMENT_REPORTS_S = purchaseAdjustmentList;

                        var fiscalObj = $(trs3[8]).find('td');
                        var auditDate="";
                        if(fiscalObj != null && fiscalObj.length == 4){
                            auditDate = $(fiscalObj).eq(3).text().trim();
                        }
                        json.FISCAL_EXPENDITURE_AUDIT_OPINION = $(fiscalObj).eq(1).text().trim();//项目本级人民政府对PPP项目合同中约定的政府跨年度财政支出责任纳入中期财政规划的审核意见
                        json.AUDIT_DATE = auditDate;//审核日期

                        //抓取--适时公开附件--信息
                        var trsPDF3 = $(tables3[1]).find('tr');//附件信息所在的table表格数据栏
                        //获取---项目采购文件、补遗文件---附件
                        var url_purchasing = $(trsPDF3[0]).find('td').eq(1).find('a');
                        var purchasingAddendumFileList = new Array();
                        var purchasingAddendumFileListNew = new Array();
                        $(url_purchasing).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.PURCHASING_ADDENDUM_FILE_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    purchasingAddendumFileList = dataArraya;
                                    purchasingAddendumFileListNew = oldJSON.PURCHASING_ADDENDUM_FILE_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 17,json.PROJ_HREF,callback);
                                        purchasingAddendumFileList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        purchasingAddendumFileListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    purchasingAddendumFileList.push(Ut.save_accessory_pdf(ob, 17,json.PROJ_HREF,callback));
                                }
                            }else{
                                purchasingAddendumFileList.push(Ut.save_accessory_pdf(ob, 17,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.PURCHASING_ADDENDUM_FILE_REPORTS = purchasingAddendumFileList;
                        }else{
                            json.PURCHASING_ADDENDUM_FILE_REPORTS = purchasingAddendumFileListNew;
                        }
                        json.PURCHASING_ADDENDUM_FILE_REPORTS_S = purchasingAddendumFileList;

                        //获取---资格预审专家评审结论性意见及资格预审专家名单---附件
                        var url_expert = $(trsPDF3[1]).find('td').eq(1).find('a');
                        var expertReviewList = new Array();
                        var expertReviewListNew = new Array();
                        $(url_expert).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.EXPERT_REVIEW_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    expertReviewList = dataArraya;
                                    expertReviewListNew = oldJSON.EXPERT_REVIEW_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 18,json.PROJ_HREF,callback);
                                        expertReviewList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        expertReviewListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    expertReviewList.push(Ut.save_accessory_pdf(ob, 18,json.PROJ_HREF,callback));
                                }
                            }else{
                                expertReviewList.push(Ut.save_accessory_pdf(ob, 18,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.EXPERT_REVIEW_REPORTS = expertReviewList;
                        }else{
                            json.EXPERT_REVIEW_REPORTS = expertReviewListNew;
                        }
                        json.EXPERT_REVIEW_REPORTS_S = expertReviewList;

                        //获取---资格预审专家评审结论性意见及资格预审专家名单---附件
                        var url_preliminary = $(trsPDF3[2]).find('td').eq(1).find('a');
                        var preliminaryHearingList = new Array();
                        var preliminaryHearingListNew = new Array();
                        $(url_preliminary).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.PRELIMINARY_HEARING_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    preliminaryHearingList = dataArraya;
                                    preliminaryHearingListNew = oldJSON.PRELIMINARY_HEARING_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 19,json.PROJ_HREF,callback);
                                        preliminaryHearingList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        preliminaryHearingListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    preliminaryHearingList.push(Ut.save_accessory_pdf(ob, 19,json.PROJ_HREF,callback));
                                }
                            }else{
                                preliminaryHearingList.push(Ut.save_accessory_pdf(ob, 19,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.PRELIMINARY_HEARING_REPORTS = preliminaryHearingList;
                        }else{
                            json.PRELIMINARY_HEARING_REPORTS = preliminaryHearingListNew;
                        }
                        json.PRELIMINARY_HEARING_REPORTS_S = preliminaryHearingList;

                        //获取---确认谈判工作组成员名单---附件
                        var url_negotiating = $(trsPDF3[3]).find('td').eq(1).find('a');
                        var negotiatingGroupMemberList = new Array();
                        var negotiatingGroupMemberListNew = new Array();
                        $(url_negotiating).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.NEGOTIATING_GROUP_MEMBER_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    negotiatingGroupMemberList = dataArraya;
                                    negotiatingGroupMemberListNew = oldJSON.NEGOTIATING_GROUP_MEMBER_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 20,json.PROJ_HREF,callback);
                                        negotiatingGroupMemberList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        negotiatingGroupMemberListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    negotiatingGroupMemberList.push(Ut.save_accessory_pdf(ob, 20,json.PROJ_HREF,callback));
                                }
                            }else{
                                negotiatingGroupMemberList.push(Ut.save_accessory_pdf(ob, 20,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.NEGOTIATING_GROUP_MEMBER_REPORTS = negotiatingGroupMemberList;
                        }else{
                            json.NEGOTIATING_GROUP_MEMBER_REPORTS = negotiatingGroupMemberListNew;
                        }
                        json.NEGOTIATING_GROUP_MEMBER_REPORTS_S = negotiatingGroupMemberList;

                        //获取---已签署的PPP项目合同---附件
                        var url_signed = $(trsPDF3[4]).find('td').eq(1).find('a');
                        var signedContractList = new Array();
                        var signedContractListNew = new Array();
                        $(url_signed).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.SIGNED_CONTRACT_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    signedContractList = dataArraya;
                                    signedContractListNew = oldJSON.SIGNED_CONTRACT_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 21,json.PROJ_HREF,callback);
                                        signedContractList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        signedContractListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    signedContractList.push(Ut.save_accessory_pdf(ob, 21,json.PROJ_HREF,callback));
                                }
                            }else{
                                signedContractList.push(Ut.save_accessory_pdf(ob, 21,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.SIGNED_CONTRACT_REPORTS = signedContractList;
                        }else{
                            json.SIGNED_CONTRACT_REPORTS = signedContractListNew;
                        }
                        json.SIGNED_CONTRACT_REPORTS_S = signedContractList;


                        //获取---本项目政府支出责任确认文件或更新调整文件，以及同级人大（或人大常委会）将本项目财政支出责任纳入跨年度预算的批复文件---附件
                        var url_budget = $(trsPDF3[5]).find('td').eq(1).find('a');
                        var budgetApprovalDocumentsList = new Array();
                        var budgetApprovalDocumentsListNew = new Array();
                        $(url_budget).each(function(){
                            //获取需要下载的问题件名和附件存储位置信息
                            var urlPDF = Ut.url_replace_special_characters($(this).attr("url"));
                            var ob=URL.parse(urlPDF, true).query;
                            if(oldJSON != null){
                                var dataArraya = oldJSON.BUDGET_APPROVAL_DOCUMENTS_REPORTS_S;
                                if(dataArraya != null && dataArraya != undefined){
                                    budgetApprovalDocumentsList = dataArraya;
                                    budgetApprovalDocumentsListNew = oldJSON.BUDGET_APPROVAL_DOCUMENTS_REPORTS;
                                    //数组中包含当前文件则不操作
                                    if(JSON.stringify(dataArraya).indexOf(ob.ftpFileName) < 0){
                                        var newArray = Ut.save_accessory_pdf(ob, 22,json.PROJ_HREF,callback);
                                        budgetApprovalDocumentsList.push(newArray);
                                        var jso1 = JSON.parse(JSON.stringify(newArray));
                                        jso1.is_save = 2;
                                        budgetApprovalDocumentsListNew.push(jso1);
                                        is_update = 2;
                                    }
                                }else{
                                    budgetApprovalDocumentsList.push(Ut.save_accessory_pdf(ob, 22,json.PROJ_HREF,callback));
                                }
                            }else{
                                budgetApprovalDocumentsList.push(Ut.save_accessory_pdf(ob, 22,json.PROJ_HREF,callback));
                            }
                        });
                        //判断等于空则表示新增数据
                        if(oldJSON == null){
                            json.BUDGET_APPROVAL_DOCUMENTS_REPORTS = budgetApprovalDocumentsList;
                        }else{
                            json.BUDGET_APPROVAL_DOCUMENTS_REPORTS = budgetApprovalDocumentsListNew;
                        }
                        json.BUDGET_APPROVAL_DOCUMENTS_REPORTS_S = budgetApprovalDocumentsList;
                    }
                    //获取执行阶段信息
                    if(projState >= 4){

                    }
                    json.IS_UPDATE = is_update;
                } catch (e) {
                    console.log(index,"==出错====proj_href===",json.PROJ_HREF);
                    console.log("get_cpppc_org_detail======", e);
                    //保存错误值数据库中
                    json.type=0;
                    Ut.save_error_list(json, 0, callback);
                }
                setTimeout(function () {
                    callback(null, response);
                }, 5000 + Math.ceil(Math.random() * 100))
                });
            });
        });
    });
    async.series(task1, function (err, result) {
        if (err) return callback(err);
        callback(null, dataArray);
    })
}

Ut.save_accessory_pdf = function (ob, type,PROJ_HREF,callback) {
    //获取URL地址
    /*var urlPDF = obj.attr("url");
    urlPDF = urlPDF.replace(/#/g,"");
    var ob=URL.parse(urlPDF, true).query;*/
    var accessory = {};
    var fileName = ob.fileName;//文件名称
    var ftpFileName = ob.ftpFileName;//原存储服务器名称
    var suffix=fileName.substring(fileName.lastIndexOf(".") + 1,fileName.length);//文件后缀
    var UUID=Math.uuidFast();//现服务器名称
    accessory.accessory_name = fileName;
    accessory.ftpFileName = ftpFileName;
    accessory.suffix_name = suffix;
    accessory.file_name = UUID;
    accessory.file_path = filePath;
    //http://www.cpppc.org:8082/efmisweb/ppp/projManage/xsg_perview.do?tokenid=null&fileName=2017/08/25/20170825045038833.pdf
    accessory.urlPDF = cpppc_url +"/ppp/projManage/xsg_perview.do?tokenid=null&fileName="+ftpFileName;
    accessory.PROJ_HREF = PROJ_HREF;//文章地址
    accessory.type = type;
    accessory.is_save = 1;
    Ut.saveFile(accessory, callback);
    return accessory;
}

//保存所有的抓取出错的列表信息
Ut.save_error_list = function (fileJson,num,callback) {
    mongodb.saveObject(errorInitial, fileJson, num, callback);
}

/**
 * 更新项目的阶段信息信息
 * 根据proj_href更新
 * @param cpppc_info
 * @param callback
 */
Ut.update_cpppc = function (cpppc_info, callback) {
    mongodb.saveByProjHref(cppp_org_item, cpppc_info, function (err, res) {
        callback(err, res);
    })
}

Ut.saveForEach = function (pdfArray ,callback) {
    try{
    if(pdfArray != null && pdfArray != undefined && pdfArray.length > 0){
        //console.log("======pdfArray.length==",pdfArray.length)
        //循环下载附件信息
        pdfArray.forEach(function (json, index) {
            Ut.saveFile(json, callback);
        });
    }
    }catch (e){console.log("出错了======", pdfArray);}
}

Ut.saveFile = function (accessory ,callback) {
    var pat=file + filePath;
    var psBoo = fs.existsSync(pat);
    //判断文件夹不存在则创建
    if(psBoo == false){
        fs.mkdirSync(pat);
    }
    request({url : accessory.urlPDF,timeout: 5000},function (error, response, body) {
        if(body == undefined){
            saveFileError(accessory ,99,callback);
        }else if(body.indexOf("您所访问的页面不存在") > 0){
            //文件不存在则清空当前附件信息
            saveFileError(accessory ,99,callback);
        }
    }).pipe(fs.createWriteStream(pat + accessory.file_name +"." + accessory.suffix_name)).on('error', function(err) {
        //文件报错后记录文件信息，抓取所有完成后，重新下载此文件
        saveFileError(accessory ,99,callback);
        console.log("==err==error==",err)
    });
}

function saveFileError(accessory ,type,callback){
    var errJson = {};
    errJson.urlPDF = accessory.urlPDF;
    errJson.accessory_name = accessory.accessory_name;
    errJson.ftpFileName = accessory.ftpFileName;
    errJson.suffix_name = accessory.suffix_name;
    errJson.file_name = accessory.file_name;
    errJson.file_path = accessory.file_path;
    errJson.type = type;
    errJson.PROJ_HREF = accessory.PROJ_HREF;
    Ut.save_error_list(errJson,1, callback);
}








//删除出错后抓取成功的列表信息
Ut.remove_error_cpppc_list = function (fileJson) {
    mongodb.removeById(errorInitial, fileJson)
}

//查询所有抓取过程中出错的信息再次循环抓取
Ut.query_error_cpppc_list = function (callback) {
    mongodb.query(errorInitial, {}, function (err, res) {
        callback(err, res);
    })
}

//抓取完成后处理请求失败数据信息
Ut.get_cpppc_list_error= function (resHref, trs, callback) {
    console.log("=-===============resHref==",resHref.length)
    var task1 = []; //顺序执行
    resHref.forEach(function (json, index) {
        task1.push(function (callback) {
            console.log("=============json==",index)
            var ccInfo = JSON.parse(JSON.stringify(json));
            delete ccInfo["_id"];
            //根据不同的类型判断需要调用的方法1、表示需要获取list的值  2、表示需要获取单个项目的信息  3、表示需要重新下载文件信息
            if(ccInfo.type == 0){
                trs.push(ccInfo);
            }else if(ccInfo.type == 99){
                //重新保存文件信息
                Ut.saveFile(ccInfo, callback);
            }
            //判断json._id不为空并且不为undefined
            if(json._id != null && json._id != undefined){
                console.log(index,"=====json._id=====",json._id)
                //更新完成后删除报错表中的数据信息
                Ut.remove_error_cpppc_list(json);
            }
            setTimeout(function () {
                callback(null, null);
            }, 500 + Math.ceil(Math.random() * 1000))
        })
    });
    async.series(task1, function (err, result) {
        console.log("===============trs=====",trs.length)
        callback(null, trs);
    })
}



/**
 * 所属行业
 * @param classify
 * @returns {*}
 */
Ut.classifyType = function (classify) {
    var ret = classify;
    switch (classify) {
        case  '能源':
            ret = '01';
            break;
        case  '交通运输':
            ret = '02';
            break;
        case  '水利建设':
            ret = '03';
            break;
        case  '生态建设和环境保护':
            ret = '04';
            break;
        case  '农业':
            ret = '05';
            break;
        case  '林业':
            ret = '06';
            break;
        case  '科技':
            ret = '07';
            break;
        case  '保障性安居工程':
            ret = '08';
            break;
        case  '医疗卫生':
            ret = '09';
            break;
        case  '养老':
            ret = '10';
            break;
        case  '教育':
            ret = '11';
            break;
        case  '文化':
            ret = '12';
            break;
        case  '体育':
            ret = '13';
            break;
        case  '市政工程':
            ret = '14';
            break;
        case  '政府基础设施':
            ret = '15';
            break;
        case  '城镇综合开发':
            ret = '16';
            break;
        case  '旅游':
            ret = '17';
            break;
        case  '社会保障':
            ret = '19';
            break;
        case  '其他':
            ret = '99';
            break;
        case  '全部':
            ret = 'all';
            break;
    }
    return ret;
}

Ut.region_num = function (region) {
    var ret = region;
    switch (region) {
        case  '北京市':
            ret = "11";
            break;
        case  '天津市':
            ret = "12";
            break;
        case  '河北省':
            ret = "13";
            break;
        case  '山西省':
            ret = "14";
            break;
        case  '内蒙古自治区':
            ret = "15";
            break;
        case  '辽宁省':
            ret = "21";
            break;
        case  '大连市':
            ret = "2102";
            break;
        case  '吉林省':
            ret = "22";
            break;
        case  '黑龙江省':
            ret = "23";
            break;
        case  '上海市':
            ret = "31";
            break;
        case  '江苏省':
            ret = "32";
            break;
        case  '浙江省':
            ret = "33";
            break;
        case  '宁波市':
            ret = "3302";
            break;
        case  '安徽省':
            ret = "34";
            break;
        case  '福建省':
            ret = "35";
            break;
        case  '厦门市':
            ret = "3502";
            break;
        case  '江西省':
            ret = "36";
            break;
        case  '山东省':
            ret = "37";
            break;
        case  '青岛市':
            ret = "3702";
            break;
        case  '河南省':
            ret = "41";
            break;
        case  '湖北省':
            ret = "42";
            break;
        case  '湖南省':
            ret = "43";
            break;
        case  '广东省':
            ret = "44";
            break;
        case  '深圳市':
            ret = "4403";
            break;
        case  '广西壮族自治区':
            ret = "45";
            break;
        case  '海南省':
            ret = "46";
            break;
        case  '重庆市':
            ret = "50";
            break;
        case  '四川省':
            ret = "51";
            break;
        case  '贵州省':
            ret = "52";
            break;
        case  '云南省':
            ret = "53";
            break;
        case  '西藏自治区':
            ret = "54";
            break;
        case  '陕西省':
            ret = "61";
            break;
        case  '甘肃省':
            ret = "62";
            break;
        case  '青海省':
            ret = "63";
            break;
        case  '宁夏回族自治区':
            ret = "64";
            break;
        case  '新疆维吾尔自治区':
            ret = "65";
            break;
        case  '新疆生产建设兵团':
            ret = "66";
            break;
        case  '台湾省':
            ret = "71";
            break;
        case  '中央本级':
            ret = "8700";
            break;
    }
    return ret;
}

Ut.url_replace_special_characters = function (urlVar) {
    return urlVar.replace(/#/g,"");
}

Ut.saveFileCeshi = function (callback) {
    var pat=file + filePath;
    var psBoo = fs.existsSync(pat);
    //判断文件夹不存在则创建
    if(psBoo == false){
        fs.mkdirSync(pat);
    }
    var UUID=Math.uuidFast();//现服务器名称
    /*request({url : "http://www.cpppc.org:8082/efmisweb/ppp/projManage/perview.do?fileName=%E5%85%B4%E5%BB%B6%E9%AB%98%E9%80%9F%E7%AB%8B%E9%A1%B9%E6%89%B9%E5%A4%8D.pdf&ftpFileName=20161130022954729.pdf&content=efmisweb&xsg=:8083/",timeout: 5000},function(error, response, body){
        console.log(error,"========================",response)
        //{url : accessory.urlPDF,timeout: 5000}
        request({url : "http://www.cpppc.org:8082/efmisweb/ppp/projManage/xsg_perview.do?tokenid=null&fileName=20170227103043297.pdf",timeout: 5000},function (error, response, body) {
            if(body == undefined){
                console.log(error,"========================undefined=",response)
            }else if(body.indexOf("您所访问的页面不存在") > 0){
                //文件不存在则清空当前附件信息
                console.log("========================0000000000000=")
            }
        }).pipe(fs.createWriteStream(pat + UUID +".pdf")).on('error', function(err) {
            //文件报错后记录文件信息，抓取所有完成后，重新下载此文件
            console.log("========================11111111=")
            console.log("==err==error==",err)
        });
    })
*/
    request({url : "http://www.cpppc.org:8082/efmisweb/ppp/projManage/perview.do?ftpFileName=20161130022954729.pdf&content=efmisweb&xsg=:8083/",timeout: 5000},function (error, response, body) {
        if(body == undefined){
            console.log(error,"========================undefined=",response)
        }else if(body.indexOf("您所访问的页面不存在") > 0){
            //文件不存在则清空当前附件信息
            console.log("========================0000000000000=")
        }
    });


}



module.exports = Ut;